<?php



/**

 * @author ducnhat

 * @email ddnhat@gmail.com

 * @copyright 2014

 */



class Default_Form_Order{

	

	protected $_isError = false;

	protected $_messageError = null;

    protected $_arrData = null;

    

    public function __construct($params = array(), $checkPhoneNumner = true){

        $translate = Zend_Registry::get('Zend_Translate');

        

        $validatorName = new Zend_Validate();

        $validatorEmail = new Zend_Validate();

        $validatorPhoneNumber = new Zend_Validate();

        

        $validatorName->addValidator(new Zend_Validate_NotEmpty(), true)

                    ->addValidator(new Zend_Validate_Alnum(true), true);

        

        $validatorEmail->addValidator(new Zend_Validate_NotEmpty(), true)

                        ->addValidator(new Zend_Validate_EmailAddress(), true);

        

        $validatorPhoneNumber->addValidator(new Zend_Validate_NotEmpty(), true)

                            ->addValidator(new Zend_Validate_Digits(), true);

        

        

        if(!$validatorName->isValid($params['name'])){

            $this->_messageError['name'] = $translate->_('name') . current($validatorName->getMessages());

            $this->_arrData['name'] = '';

            $this->_isError = true;

        }else{

            $this->_arrData['name'] = $params['name'];

        }

        

        if(!$validatorEmail->isValid($params['email'])){

            $this->_messageError['email'] = $translate->_('email') . current($validatorEmail->getMessages());

            $this->_arrData['email'] = '';

            $this->_isError = true;

        }else{

            $this->_arrData['email'] = $params['email'];

        }

        
        if($checkPhoneNumner){
            if(!$validatorPhoneNumber->isValid($params['phone_number'])){
    
                $this->_messageError['phone_number'] = $translate->_('phone number') . current($validatorPhoneNumber->getMessages());
    
                $this->_arrData['phone_number'] = '';
    
                $this->_isError = true;
    
            }else{
    
                $this->_arrData['phone_number'] = $params['phone_number'];
    
            }
        }

        

        $date = new Zend_Date();

        $curDate = $date->get(Zend_Registry::get('date_format_insert'));

        

        $this->_arrData['date'] = $curDate;
        
        if(isset($params['address'])){
            $this->_arrData['address'] = $params['address'];
        }

        $this->_arrData['status'] = 'not paid';

    }

    

    public function isError(){

    	return $this->_isError;

    }

    

    public function getMessageError(){

        return $this->_messageError;

    }

    

    public function getData(){

        return $this->_arrData;

    }

}